<template>
    <el-dialog v-model="dialog_visible" title="下载专区" width="512px">
        <!-- 一级 -->
        <el-form :model="form" label-width="120px" size="large">
            <el-form-item label="下载链接" required>
                <el-input v-model="link" type="textarea" placeholder="请输入下载链接" />
            </el-form-item>
            <el-form-item label="">
                <el-button type="primary" @click="handleSubmit"
                    v-if="userStore.info_data.role == 'organizing'">确定修改</el-button>
                <el-button type="primary" @click="handleJumpLink" v-else>点击跳转</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>
<script setup >
import { onMounted, ref } from 'vue'
import { useUserStore } from "@/store/user"
import { ElMessage } from "element-plus";
import { getSysConfig, updateSysConfig } from '@/api/manage/index.js'
const userStore = useUserStore();
const dialog_visible = ref(false);
const link = ref("")
const id = ref('')
const handleOpenModal = () => {
    dialog_visible.value = true
}
// 获取配置
const handlegetSysConfig = async () => {
    let res = await getSysConfig()
    if (res.success) {
        link.value = res.entity.content
        id.value = res.entity.id
    }
}
// 提交接口
const handleSubmit = async () => {
    // TODO 判断连接是否正确
    let res = await updateSysConfig({
        id: id.value,
        content: link.value
    })
    if (res.success) {
        ElMessage.success(res.message)
    }
    dialog_visible.value = false
}
// 跳转到链接
const handleJumpLink = () => {
    window.open(link.value);
}
defineExpose({
    handleOpenModal
})
onMounted(() => {
    handlegetSysConfig()
})
</script>
<style lang="scss" scoped></style>